<?php

class AdminController extends Controller {
    public $packageAdmin;
    /**
     * Setup the layout used by the controller.
     *
     * @return void
     */
    protected function setupLayout()
    {
        if (!is_null($this->layout))
        {
            $this->layout = View::make($this->layout);
        }
    }

    public function __construct() {
        $this->packageAdmin = Config::get('constants.PACKAGE_ADMIN');
        View::share('packageAdmin', $this->packageAdmin);

        if (Auth::check()) {
            $routeAction    =  preg_split("/@/", Route::currentRouteAction());
            $controllerName =  isset($routeAction[0]) ? $routeAction[0]: '';
            $actionName     =  isset($routeAction[1]) ? $routeAction[1]: '';
            // To layout header
            View::share('controllerName', $controllerName);
            View::share('actionName', $actionName);
        } else {
            return Redirect::guest($this->packageAdmin.'/admin/login')->with('success', 'Please login with email and password');
        }
    }
}
